package stack_queue

import "container/list"

func NewMyStackQ() *MyStackQ {
	return &MyStackQ{data: list.New(), help: list.New()}
}

type MyStackQ struct {
	data *list.List
	help *list.List
}

func (s *MyStackQ) Push (val int) {
	s.data.PushBack(val)
}

func (s *MyStackQ) Pop () int {
	if s.data.Len() == 0 {
		panic("stack was empty can't pop !!!")
	}
	for s.data.Len() != 1 {
		s.help.PushBack(s.data.Remove(s.data.Front()))
	}
	ans := s.data.Remove(s.data.Front()).(int)
	s.data, s.help = s.help, s.data
	return ans
}

func (s *MyStackQ) IsEmpty () bool {
	return s.data.Len() == 0
}


